<template>
  <div class="app-container">
    <el-form v-show="showSearch" ref="queryForm" :model="queryParams" size="small" :inline="true" label-width="68px">
      <!-- <el-form-item label="支付方式" prop="payMethod">
        <el-select v-model="queryParams.payMethod" placeholder="请选择支付方式：1、微信小程序支付" clearable>
          <el-option
            v-for="dict in dict.type.app_order_pay_method"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="订单号" prop="tradeNo">
        <el-input
          v-model="queryParams.tradeNo"
          placeholder="请输入订单号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="全用户id" prop="accountUserId">
        <el-input
          v-model="queryParams.accountUserId"
          placeholder="请输入全平台用户id"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="收件地址" prop="addrId">
        <el-input
          v-model="queryParams.addrId"
          placeholder="请输入收件地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="负责部门" prop="deptId">
        <el-input
          v-model="queryParams.deptId"
          placeholder="请输入订单负责部门ID"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="订单状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择订单状态,1:订单创建成功、2：支付成功、3：交易完结" clearable>
          <el-option
            v-for="dict in dict.type.app_order_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item> -->
      <el-form-item label="配送状态" prop="delvStatus">
        <el-select v-model="queryParams.delvStatus" placeholder="请选择配送状态" clearable>
          <el-option
            v-for="dict in dict.type.app_order_delv_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="配送方式" prop="delvMode">
        <el-select v-model="queryParams.delvMode" placeholder="请选择配送方式，" clearable>
          <el-option
            v-for="dict in dict.type.app_order_delv_mode"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <!-- <el-form-item label="是否加急" prop="tag">
        <el-input
          v-model="queryParams.tag"
          placeholder="请输入订单标识，0：普通订单、1：加急订单"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="预约时间" prop="aptTime">
        <el-date-picker
          v-model="queryParams.aptTime"
          clearable
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择预约时间"
        />
      </el-form-item> -->
      <!-- <el-form-item label="配送地址" prop="addrDetail">
        <el-input
          v-model="queryParams.addrDetail"
          placeholder="请输入订单配送地址"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="创建时间">
        <el-date-picker
          v-model="daterangeCreateTime"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <!-- <el-form-item label="是否删除" prop="isDeleted">
        <el-input
          v-model="queryParams.isDeleted"
          placeholder="请输入是否删除，1：是、0：否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="发货时间" prop="deliverTime">
        <el-date-picker
          v-model="queryParams.deliverTime"
          clearable
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择发货时间"
        />
      </el-form-item> -->
      <!-- <el-form-item label="订单类别" prop="category">
        <el-input
          v-model="queryParams.category"
          placeholder="请输入订单类别，标记商品类别"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item label="服务员" prop="waiter">
        <el-input
          v-model="queryParams.waiter"
          placeholder="请输入服务员"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="支付状态" prop="payStatus">
        <el-select v-model="queryParams.payStatus" placeholder="请选择支付状态，1：待支付、2：支付中、3：支付成功" clearable>
          <el-option
            v-for="dict in dict.type.app_order_pay_status"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="用户昵称" prop="uNick">
        <el-input
          v-model="queryParams.uNick"
          placeholder="请输入下单用户昵称"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="用户号码" prop="uPhone">
        <el-input
          v-model="queryParams.uPhone"
          placeholder="请输入下单用户号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <!-- <el-form-item label="外部流水号" prop="prepayId">
        <el-input
          v-model="queryParams.prepayId"
          placeholder="请输入外部支付流水号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <!-- <el-form-item label="是否跨区" prop="isCrossRegion">
        <el-input
          v-model="queryParams.isCrossRegion"
          placeholder="请输入是否跨区，1：是、0：否"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPermi="['taskhub:order:add']"
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
        >新增</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPermi="['taskhub:order:edit']"
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
        >修改</el-button>
      </el-col> -->
      <!-- <el-col :span="1.5">
        <el-button
          v-hasPermi="['taskhub:order:remove']"
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
        >删除</el-button>
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['taskhub:order:export']"
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
        >导出</el-button>
      </el-col>
      <right-toolbar :show-search.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="orderList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="ID" align="center" prop="id" />
      <!-- <el-table-column label="支付方式" align="center" prop="payMethod">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_pay_method" :value="scope.row.payMethod" />
        </template>
      </el-table-column> -->
      <el-table-column label="订单号" align="center" prop="tradeNo" />
      <!-- <el-table-column label="平台用户id" align="center" prop="accountUserId" /> -->
      <!-- <el-table-column label="收件地址" align="center" prop="addrId" /> -->
      <!-- <el-table-column label="负责部门" align="center" prop="deptId" /> -->
      <!-- <el-table-column label="订单状态" align="center" prop="status">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_status" :value="scope.row.status" />
        </template>
      </el-table-column> -->
      <el-table-column label="用户昵称" align="center" prop="uNick" />
      <el-table-column label="订单类别" align="center" prop="category">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_category" :value="scope.row.category" />
        </template>
      </el-table-column>
      <el-table-column label="下单时间" align="center" prop="createTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.aptTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="配送状态" align="center" prop="delvStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_delv_status" :value="scope.row.delvStatus" />
        </template>
      </el-table-column>
      <el-table-column label="配送方式" align="center" prop="delvMode">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_delv_mode" :value="scope.row.delvMode" />
        </template>
      </el-table-column>
      <el-table-column label="用户号码" align="center" prop="uPhone" />
      <el-table-column label="入户临时密码" align="center" prop="intoPwd" />
      <el-table-column label="订单标识" align="center" prop="tag">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_tag" :value="scope.row.tag" />
        </template>
      </el-table-column>
      <el-table-column label="订单总金额" align="center" prop="totalAmount" />
      <el-table-column label="实际支付金额" align="center" prop="realPayAmount" />
      <el-table-column label="预约时间" align="center" prop="aptTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.aptTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="取件截图" align="center" prop="attachFiles">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.attachFileList.length > 0"
            style="width: 100px; height: 100px"
            :src="scope.row.attachFileList[0]"
            :preview-src-list="scope.row.attachFileList"
          />
        </template>
      </el-table-column>
      <el-table-column label="订单配送地址" align="center" prop="addrDetail" />
      <el-table-column label="下单信息描述" align="center" prop="attachText" />
      <el-table-column label="下单备注" align="center" prop="remark" />
      <!-- <el-table-column label="用户id" align="center" prop="appUserId" /> -->
      <!-- <el-table-column label="是否删除" align="center" prop="isDeleted" /> -->
      <!-- <el-table-column label="支付成功时间" align="center" prop="payTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="发货时间" align="center" prop="deliverTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.deliverTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="交易成功时间" align="center" prop="successTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.successTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="订单关闭时间" align="center" prop="closeTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.closeTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="订单类型" align="center" prop="type" /> -->
      <el-table-column label="订单类别" align="center" prop="category">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_category" :value="scope.row.category" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="服务员ID" align="center" prop="waiterId" /> -->
      <el-table-column label="服务员员" align="center" prop="waiter" />
      <el-table-column label="服务员员电话" align="center" prop="waiterPhone" />
      <!-- <el-table-column label="核实后的价格" align="center" prop="verifyAmount" /> -->
      <el-table-column label="接单时间" align="center" prop="takeTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.takeTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="取件备注" align="center" prop="pickRmk" />
      <el-table-column label="取件时间" align="center" prop="pickTime" width="180">
        <!-- <template slot-scope="scope">
          <span>{{ parseTime(scope.row.pickTime, '{y}-{m}-{d}') }}</span>
        </template> -->
      </el-table-column>
      <el-table-column label="送达照片" align="center" prop="arrivePhotos">
        <template slot-scope="scope">
          <el-image
            v-if="scope.row.arrivePhotoList.length > 0"
            style="width: 100px; height: 100px"
            :src="scope.row.arrivePhotoList[0]"
            :preview-src-list="scope.row.arrivePhotoList"
          />
        </template>
      </el-table-column>
      <el-table-column label="送达备注" align="center" prop="arriveRmk" />
      <el-table-column label="送达时间" align="center" prop="arriveTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.arriveTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="支付状态" align="center" prop="payStatus">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.app_order_pay_status" :value="scope.row.payStatus" />
        </template>
      </el-table-column>
      <!-- <el-table-column label="外部支付流水号" align="center" prop="prepayId" /> -->
      <!-- <el-table-column label="是否跨区" align="center" prop="isCrossRegion" /> -->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['taskhub:AppOrderItem:list']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="oepnPage(scope.row,'/taskhub/AppOrderitem')"
          >订单详情</el-button>
          <!-- <el-button
            v-hasPermi="['taskhub:order:edit']"
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >详情</el-button> -->
          <el-button
            v-hasPermi="['taskhub:order:remove']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改订单对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="支付方式" prop="payMethod">
          <el-select v-model="form.payMethod" placeholder="请选择支付方式：1、微信小程序支付">
            <el-option
              v-for="dict in dict.type.app_order_pay_method"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="订单号" prop="tradeNo">
          <el-input v-model="form.tradeNo" placeholder="请输入订单号" />
        </el-form-item>
        <el-form-item label="全平台用户id" prop="accountUserId">
          <el-input v-model="form.accountUserId" placeholder="请输入全平台用户id" />
        </el-form-item>
        <el-form-item label="收件地址" prop="addrId">
          <el-input v-model="form.addrId" placeholder="请输入收件地址" />
        </el-form-item>
        <el-form-item label="订单负责部门ID" prop="deptId">
          <el-input v-model="form.deptId" placeholder="请输入订单负责部门ID" />
        </el-form-item>
        <el-form-item label="订单状态" prop="status">
          <el-select v-model="form.status" placeholder="请选择订单状态,1:订单创建成功、2：支付成功、3：交易完结">
            <el-option
              v-for="dict in dict.type.app_order_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="配送状态" prop="delvStatus">
          <el-select v-model="form.delvStatus" placeholder="请选择配送状态">
            <el-option
              v-for="dict in dict.type.app_order_delv_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="配送方式，" prop="delvMode">
          <el-select v-model="form.delvMode" placeholder="请选择配送方式，">
            <el-option
              v-for="dict in dict.type.app_order_delv_mode"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="入户临时密码" prop="intoPwd">
          <el-input v-model="form.intoPwd" placeholder="请输入入户临时密码" />
        </el-form-item>
        <el-form-item label="订单标识" prop="tag">
          <el-input v-model="form.tag" placeholder="请输入订单标识，0：普通订单、1：加急订单" />
        </el-form-item>
        <el-form-item label="订单总金额" prop="totalAmount">
          <el-input v-model="form.totalAmount" placeholder="请输入订单总金额" />
        </el-form-item>
        <el-form-item label="实际支付金额" prop="realPayAmount">
          <el-input v-model="form.realPayAmount" placeholder="请输入实际支付金额" />
        </el-form-item>
        <el-form-item label="预约时间" prop="aptTime">
          <el-date-picker
            v-model="form.aptTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择预约时间"
          />
        </el-form-item>
        <el-form-item label="附加文件地址" prop="attachFiles">
          <el-input v-model="form.attachFiles" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="订单配送地址" prop="addrDetail">
          <el-input v-model="form.addrDetail" placeholder="请输入订单配送地址" />
        </el-form-item>
        <el-form-item label="下单信息描述" prop="attachText">
          <el-input v-model="form.attachText" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="下单备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="子应用用户id" prop="appUserId">
          <el-input v-model="form.appUserId" placeholder="请输入子应用用户id" />
        </el-form-item>
        <el-form-item label="是否删除" prop="isDeleted">
          <el-input v-model="form.isDeleted" placeholder="请输入是否删除，1：是、0：否" />
        </el-form-item>
        <el-form-item label="支付成功时间" prop="payTime">
          <el-date-picker
            v-model="form.payTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择支付成功时间"
          />
        </el-form-item>
        <el-form-item label="发货时间" prop="deliverTime">
          <el-date-picker
            v-model="form.deliverTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择发货时间"
          />
        </el-form-item>
        <el-form-item label="交易成功时间" prop="successTime">
          <el-date-picker
            v-model="form.successTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择交易成功时间"
          />
        </el-form-item>
        <el-form-item label="订单关闭时间" prop="closeTime">
          <el-date-picker
            v-model="form.closeTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择订单关闭时间"
          />
        </el-form-item>
        <el-form-item label="订单类别" prop="category">
          <el-input v-model="form.category" placeholder="请输入订单类别，标记商品类别" />
        </el-form-item>
        <el-form-item label="服务员ID" prop="waiterId">
          <el-input v-model="form.waiterId" placeholder="请输入服务员ID" />
        </el-form-item>
        <el-form-item label="服务员" prop="waiter">
          <el-input v-model="form.waiter" placeholder="请输入服务员" />
        </el-form-item>
        <el-form-item label="配送员电话" prop="waiterPhone">
          <el-input v-model="form.waiterPhone" placeholder="请输入配送员电话" />
        </el-form-item>
        <el-form-item label="服务员核实后的价格" prop="verifyAmount">
          <el-input v-model="form.verifyAmount" placeholder="请输入服务员核实后的价格" />
        </el-form-item>
        <el-form-item label="接单时间" prop="takeTime">
          <el-date-picker
            v-model="form.takeTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择接单时间"
          />
        </el-form-item>
        <el-form-item label="取件备注" prop="pickRmk">
          <el-input v-model="form.pickRmk" placeholder="请输入取件备注" />
        </el-form-item>
        <el-form-item label="取件时间" prop="pickTime">
          <el-date-picker
            v-model="form.pickTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择取件时间"
          />
        </el-form-item>
        <el-form-item label="送达照片" prop="arrivePhotos">
          <el-input v-model="form.arrivePhotos" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="送达备注" prop="arriveRmk">
          <el-input v-model="form.arriveRmk" type="textarea" placeholder="请输入内容" />
        </el-form-item>
        <el-form-item label="送达时间" prop="arriveTime">
          <el-date-picker
            v-model="form.arriveTime"
            clearable
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择送达时间"
          />
        </el-form-item>
        <el-form-item label="支付状态" prop="payStatus">
          <el-select v-model="form.payStatus" placeholder="请选择支付状态，1：待支付、2：支付中、3：支付成功">
            <el-option
              v-for="dict in dict.type.app_order_pay_status"
              :key="dict.value"
              :label="dict.label"
              :value="parseInt(dict.value)"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="下单用户昵称" prop="uNick">
          <el-input v-model="form.uNick" placeholder="请输入下单用户昵称" />
        </el-form-item>
        <el-form-item label="下单用户号码" prop="uPhone">
          <el-input v-model="form.uPhone" placeholder="请输入下单用户号码" />
        </el-form-item>
        <el-form-item label="外部支付流水号" prop="prepayId">
          <el-input v-model="form.prepayId" placeholder="请输入外部支付流水号" />
        </el-form-item>
        <el-form-item label="是否跨区" prop="isCrossRegion">
          <el-input v-model="form.isCrossRegion" placeholder="请输入是否跨区，1：是、0：否" />
        </el-form-item>
        <!-- <el-divider content-position="center">订单快照信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddSysOrderItem">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteSysOrderItem">删除</el-button>
          </el-col>
        </el-row>
        <el-table ref="sysOrderItem" :data="sysOrderItemList" :row-class-name="rowSysOrderItemIndex" @selection-change="handleSysOrderItemSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50" />
          <el-table-column label="商品id" prop="productId" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.productId" placeholder="请输入商品id" />
            </template>
          </el-table-column>
          <el-table-column label="商品名称" prop="productName" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.productName" placeholder="请输入商品名称" />
            </template>
          </el-table-column>
          <el-table-column label="商品封面图" prop="cover" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.cover" placeholder="请输入商品封面图" />
            </template>
          </el-table-column>
          <el-table-column label="下单商品数量" prop="num" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.num" placeholder="请输入下单商品数量" />
            </template>
          </el-table-column>
          <el-table-column label="商品单价" prop="unitPrice" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.unitPrice" placeholder="请输入商品单价" />
            </template>
          </el-table-column>
          <el-table-column label="商品合计价格" prop="countPrice" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.countPrice" placeholder="请输入商品合计价格= 商品单价*商品数量" />
            </template>
          </el-table-column>
          <el-table-column label="商品描述" prop="descr" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.descr" placeholder="请输入商品描述" />
            </template>
          </el-table-column>
          <el-table-column label="商品规格ID" prop="specId" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.specId" placeholder="请输入商品规格ID" />
            </template>
          </el-table-column>
        </el-table> -->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listOrder, getOrder, delOrder, addOrder, updateOrder } from '@/api/taskhub/sysOrder'

export default {
  name: 'Order',
  dicts: ['app_order_delv_status', 'app_order_pay_status', 'app_order_status', 'app_order_pay_method', 'app_order_delv_mode', 'app_order_tag', 'app_order_category'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedSysOrderItem: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 订单表格数据
      orderList: [],
      // 订单快照表格数据
      sysOrderItemList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 商品规格ID时间范围
      daterangeCreateTime: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        payMethod: null,
        tradeNo: null,
        accountUserId: null,
        addrId: null,
        deptId: null,
        status: null,
        delvStatus: null,
        delvMode: null,
        tag: null,
        aptTime: null,
        addrDetail: null,
        createTime: null,
        isDeleted: null,
        deliverTime: null,
        type: null,
        category: null,
        waiter: null,
        payStatus: null,
        uNick: null,
        uPhone: null,
        prepayId: null,
        isCrossRegion: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        payMethod: [
          { required: true, message: '支付方式：1、微信小程序支付不能为空', trigger: 'change' }
        ],
        tradeNo: [
          { required: true, message: '订单号不能为空', trigger: 'blur' }
        ],
        accountUserId: [
          { required: true, message: '全平台用户id不能为空', trigger: 'blur' }
        ],
        addrId: [
          { required: true, message: '收件地址不能为空', trigger: 'blur' }
        ],
        deptId: [
          { required: true, message: '订单负责部门ID不能为空', trigger: 'blur' }
        ],
        status: [
          { required: true, message: '订单状态,1:订单创建成功、2：支付成功、3：交易完结不能为空', trigger: 'change' }
        ],
        totalAmount: [
          { required: true, message: '订单总金额不能为空', trigger: 'blur' }
        ],
        createTime: [
          { required: true, message: '订单创建时间不能为空', trigger: 'blur' }
        ],
        payStatus: [
          { required: true, message: '支付状态，1：待支付、2：支付中、3：支付成功不能为空', trigger: 'change' }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询订单列表 */
    getList() {
      this.loading = true
      this.queryParams.params = {}
      if (this.daterangeCreateTime != null && this.daterangeCreateTime !== '') {
        this.queryParams.params['beginCreateTime'] = this.daterangeCreateTime[0]
        this.queryParams.params['endCreateTime'] = this.daterangeCreateTime[1]
      }
      listOrder(this.queryParams).then(response => {
        this.orderList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    oepnPage(row, path) {
      // 带参数跳转
      this.$router.push({ path: path, query: { itemId: row.id }})
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        payMethod: null,
        tradeNo: null,
        accountUserId: null,
        addrId: null,
        deptId: null,
        status: null,
        delvStatus: null,
        delvMode: null,
        intoPwd: null,
        tag: null,
        totalAmount: null,
        realPayAmount: null,
        aptTime: null,
        attachFiles: null,
        addrDetail: null,
        attachText: null,
        remark: null,
        createTime: null,
        appUserId: null,
        isDeleted: null,
        payTime: null,
        deliverTime: null,
        successTime: null,
        closeTime: null,
        type: null,
        category: null,
        waiterId: null,
        waiter: null,
        waiterPhone: null,
        verifyAmount: null,
        takeTime: null,
        pickRmk: null,
        pickTime: null,
        arrivePhotos: null,
        arriveRmk: null,
        arriveTime: null,
        payStatus: null,
        updateTime: null,
        uNick: null,
        uPhone: null,
        prepayId: null,
        isCrossRegion: null
      }
      this.sysOrderItemList = []
      this.resetForm('form')
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeCreateTime = []
      this.resetForm('queryForm')
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = '添加订单'
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data
        this.sysOrderItemList = response.data.sysOrderItemList
        this.open = true
        this.title = '修改订单'
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs['form'].validate(valid => {
        if (valid) {
          this.form.sysOrderItemList = this.sysOrderItemList
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess('修改成功')
              this.open = false
              this.getList()
            })
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess('新增成功')
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除订单编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess('删除成功')
      }).catch(() => {})
    },
    /** 订单快照序号 */
    rowSysOrderItemIndex({ row, rowIndex }) {
      row.index = rowIndex + 1
    },
    /** 订单快照添加按钮操作 */
    handleAddSysOrderItem() {
      const obj = {}
      obj.productId = ''
      obj.productName = ''
      obj.cover = ''
      obj.num = ''
      obj.unitPrice = ''
      obj.countPrice = ''
      obj.descr = ''
      obj.specId = ''
      this.sysOrderItemList.push(obj)
    },
    /** 订单快照删除按钮操作 */
    handleDeleteSysOrderItem() {
      if (this.checkedSysOrderItem.length === 0) {
        this.$modal.msgError('请先选择要删除的订单快照数据')
      } else {
        const sysOrderItemList = this.sysOrderItemList
        const checkedSysOrderItem = this.checkedSysOrderItem
        this.sysOrderItemList = sysOrderItemList.filter(function(item) {
          return checkedSysOrderItem.indexOf(item.index) === -1
        })
      }
    },
    /** 复选框选中数据 */
    handleSysOrderItemSelectionChange(selection) {
      this.checkedSysOrderItem = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.queryParams.params = {}
      if (this.daterangeCreateTime != null && this.daterangeCreateTime !== '') {
        this.queryParams.params['beginCreateTime'] = this.daterangeCreateTime[0]
        this.queryParams.params['endCreateTime'] = this.daterangeCreateTime[1]
      }
      this.download('taskhub/sysOrder/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
}
</script>
